package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.exception.ManagerUserException;
import com.itany.pojo.ManagerUser;
import com.itany.service.ManagerUserService;
import com.itany.vo.ActionResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.rmi.ServerException;
import java.util.HashMap;
import java.util.Map;

/**
 * Author:梁辰
 * 时间:19-4-3 上午10:14
 * description:
 * version:1.0
 */
@RestController
@RequestMapping("/managerUser")
public class ManagerUserController {
    @Resource
    ManagerUserService managerUserService;
    @RequestMapping("/findAll")
    public Map<String,Object> findAll(@RequestParam(defaultValue="1")Integer page,
                                      @RequestParam(defaultValue="10")Integer rows) {

        Map<String, Object> map = new HashMap<String, Object>();
        PageInfo<ManagerUser> info = managerUserService.findUserAll(page, rows);
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;
    }
    @RequestMapping("/login")
    public ActionResult login(ManagerUser user, HttpSession session) throws ManagerUserException, ServerException {
        ActionResult rs = new ActionResult();
        ManagerUser managerUser = managerUserService.login(user);
//        managerUser.setPassword(null);
        session.setAttribute("sessionUser",managerUser);
        rs.setStatus(true);
        return rs;
    }
}
